package com.example.validatestudy.demos.algorithm.sort;

/**
 * @param
 * @version v1
 * @auther WANGZHENFANG004
 * @summary 冒泡排序
 * @since 2024 06 25 15 06
 */
public class BubbleSort {

    public static void main(String[] args){

        int[] arr = {20,40,30,10,60,50};
        arr = bubbleSort(arr);
        for(int i=0;i<arr.length;i++){
            System.out.println(arr[i]);
        }
    }

    public static int[] bubbleSort(int[] arr){
        for(int i=0;i<arr.length;i++){
            for(int j=0;j<arr.length-i-1;j++){
                int max = arr[j];
                if(max>arr[j+1]){
                    arr[j] = arr[j+1];
                    arr[j+1] = max;
                }
            }
        }
        return arr;
    }



}
